#ifndef __DataProcessor__
#define __DataProcessor__

#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Exception.h"
#include <iostream>
#include "command.h"
#include "../client/log.h"
#include "dbstructure.h"
#include "DBUtils.h"

using Poco::Net::ServerSocket;
using Poco::Net::StreamSocket;

class DataProcessor
{
public:
    DataProcessor(){}
    ~DataProcessor(){}

    static bool Process(char* pPacket, int nSize, PServerResponse pOut);
private:
    static bool doRegistration(int nSize, char* pData, PServerResponse pOut);
    static bool doHeartbeat(int nSize, char* pData, PServerResponse pOut);
    static bool doLogin(int nSize, char* pData, PServerResponse pOut);
    static bool doChangePassword(int nSize, char* pData, PServerResponse pOut);
    static bool doUnBind(int nSize, char* pData, PServerResponse pOut);

    static bool unuseHandler(request_data* rd, PServerResponse pOut, db_keys* pKey);
    static bool registeredHandler(request_data* rd, PServerResponse pOut, db_keys* pKey);
    static bool GetResponseData(int cmd_type, string key, PServerResponse pOut, db_user *pUser, db_keys* pKey);
    static bool MakeResponseData(db_keys*, db_user*, PProductKeyInfo pKI);
    static bool error(PServerResponse pOut, int nCmdType = Cmd_Invalid, int nCmdState = Fail);
    static bool Test(PServerResponse pOut);

    static int  ValidateAllUserInfo(request_data* pRD, db_user* pUser);
    static int  ValidateLoginInfo(request_data* pRD, db_user* pUser);
    static int  ValidateUnBindInfo(request_data* pRD, db_user* pUser);
};
#endif